//
//  SXTNavgationController.m
//  SXT
//
//  Created by 赵金鹏 on 16/8/9.
//  Copyright © 2016年 赵金鹏. All rights reserved.
//

#import "SXTNavgationController.h"

@interface SXTNavgationController ()

@end

@implementation SXTNavgationController
//保证只对navbar进行一次设置，节约性能
+ (void)initialize{
    //获取UINavgationBar
    UINavigationBar *navBar = [UINavigationBar appearance];
    
    //设置navBar的背景图片
    [navBar setBackgroundImage:[UIImage imageNamed:@"nav_backImage"] forBarMetrics:(UIBarMetricsDefault)];
    
    //设置导航栏字体样式
    [navBar setTitleTextAttributes:@{
                                     NSForegroundColorAttributeName:[UIColor blackColor],
                                     NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f]
                                     }];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count) {
        UIButton *backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        backBtn.frame = CGRectMake(0, 0, 30, 30);
        [backBtn setImage:[UIImage imageNamed:@"详情界面返回按钮"] forState:(UIControlStateNormal)];
        [backBtn addTarget:self action:@selector(returnViewController) forControlEvents:(UIControlEventTouchUpInside)];
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
        viewController.navigationItem.leftBarButtonItem = backItem;
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}

- (void)returnViewController{
    [self popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
